﻿using System;

namespace HoverTreeMobile.HvtAdmin.HvtPicture
{
    public partial class GetPictureByUrl : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnImg_Click(object sender, EventArgs e)
        {
            try
            {
                System.Net.WebClient m_hvtWebClient = new System.Net.WebClient();
                

                //如果不是指定格式图片
                //例如http://hovertree.com/hvtart/bjae/t2lo8pf7.htm 是htm文件，不是图片
                if (!(textBoxImgUrl.Text.EndsWith(".jpg")
                    || textBoxImgUrl.Text.EndsWith(".gif")
                    || textBoxImgUrl.Text.EndsWith(".png")))
                {
                    ltlTips.Text = "输入的不是指定格式的图片的网址";

                    return;
                }

                //生成随机的图片文件名
                string m_picFileName = HoverTree.HoverTreeFrame.Utils.GenHvtStr()+ HoverTree.HoverTreeFrame.HoverString.GetLastStr(textBoxImgUrl.Text,4);

                string m_keleyiPicture = Server.MapPath("/hovertreeimages/"+ m_picFileName);
                //根据网址下载文件
                m_hvtWebClient.DownloadFile(textBoxImgUrl.Text, m_keleyiPicture);

                hvtImg.ImageUrl = "/hovertreeimages/" + m_picFileName;
                ltlTips.Text = string.Empty;
            }
            catch(Exception ex)
            {
                ltlTips.Text = ex.ToString();
            }
        }
    }
}